<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  

  
  <title>Threadv</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta property="og:type" content="website">
<meta property="og:title" content="Threadv">
<meta property="og:url" content="http://yoursite.com/index.html">
<meta property="og:site_name" content="Threadv">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Threadv">
  
    <link rel="alternate" href="/atom.xml" title="Threadv" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  <link rel="stylesheet" href="/css/style.css">
</head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">Threadv</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Suche"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://yoursite.com"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main">
  
    <article id="post-linux/linux_shell" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2020/05/17/linux/linux_shell/" class="article-date">
  <time datetime="2020-05-17T05:02:19.000Z" itemprop="datePublished">2020-05-17</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2020/05/17/linux/linux_shell/">linux—shell</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h5 id="linux—shell"><a href="#linux—shell" class="headerlink" title="linux—shell"></a>linux—shell</h5><ul>
<li>文件</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">❖ 磁盘与⽬录：df、ls、cd、pwd、$PWD </span><br><span class="line">❖ ⽂件编辑：交互编辑vim、流式编辑器 sed </span><br><span class="line">❖ ⽂件权限：chmod、chown </span><br><span class="line">❖ ⽂件搜索：ﬁnd </span><br><span class="line">❖ ⽂件内容：cat、more、less、grep </span><br><span class="line">❖ 特殊⽂件：软链、socket：进程通讯、管道：进程通讯</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> 文件权限</span></span><br><span class="line"></span><br><span class="line">❖ ls -l 查看权限 </span><br><span class="line">❖ ⽂件、⽬录 </span><br><span class="line">❖ ⽤户、组 </span><br><span class="line">❖ 读、写、执⾏、SUID、SGID </span><br><span class="line">❖ chmod：修改文件文件夹权限 </span><br><span class="line">❖ chgrp：修改归属组</span><br><span class="line">❖ chown：修改用户权限</span><br></pre></td></tr></table></figure>
<ul>
<li><p>进程</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">❖ top cpu使用情况 </span><br><span class="line">❖ ps  查看进程</span><br></pre></td></tr></table></figure>
</li>
<li><p>网络</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">❖ netstat -tlnp</span><br></pre></td></tr></table></figure>
</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">(No info could be read for &quot;-p&quot;: geteuid()=2313 but you should be root.)</span><br><span class="line">Active Internet connections (only servers)</span><br><span class="line">Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name</span><br><span class="line">tcp        0      0 0.0.0.0:9992            0.0.0.0:*               LISTEN      -</span><br><span class="line">tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      -</span><br><span class="line">tcp        0      0 127.0.0.1:9101          0.0.0.0:*               LISTEN      -</span><br><span class="line">tcp        0      0 0.0.0.0:9102            0.0.0.0:*               LISTEN      -</span><br><span class="line">tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      -</span><br><span class="line">tcp        0      0 0.0.0.0:9009            0.0.0.0:*               LISTEN      -</span><br></pre></td></tr></table></figure>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">❖ netstat -tnp</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">(No info could be read for &quot;-p&quot;: geteuid()=2313 but you should be root.)</span><br><span class="line">Active Internet connections (w/o servers)</span><br><span class="line">Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name</span><br><span class="line">tcp        0      0 127.0.0.1:25            127.0.0.1:59170         TIME_WAIT   -</span><br><span class="line">tcp        0      0 172.19.147.8:22         183.39.174.181:48950    ESTABLISHED -</span><br><span class="line">tcp        0      1 172.19.147.8:35712      101.132.159.87:25       SYN_SENT    -</span><br><span class="line">tcp        0      0 127.0.0.1:9101          127.0.0.1:59622         TIME_WAIT   -</span><br><span class="line">tcp        0      0 172.19.147.8:22         114.95.222.59:55940     ESTABLISHED -</span><br></pre></td></tr></table></figure>
<ul>
<li>Shell 输⼊输出<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">❖ Read ⽤来读取输⼊，并赋值给变量 </span><br><span class="line">❖ echo ，printf可以简单输出变量。 </span><br><span class="line">❖ &gt; ﬁle  将输出重定向到另⼀个⽂件 </span><br><span class="line">❖ &gt;&gt; 表⽰追加 等价于tee -a </span><br><span class="line">❖ &lt; ﬁle  输⼊重定向 </span><br><span class="line">❖ |   表⽰管道，也就是前⼀个命令的输出传⼊下⼀个命令的输⼊</span><br></pre></td></tr></table></figure></li>
</ul>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2020/05/17/linux/linux_shell/" data-id="ckcc5iwou007qq4uworaopa3s" class="article-share-link">Teilen</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/linux/">linux</a></li></ul>

    </footer>
  </div>
  
</article>


  
    <article id="post-linux/linux_awk_sed" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2020/05/16/linux/linux_awk_sed/" class="article-date">
  <time datetime="2020-05-16T07:02:19.000Z" itemprop="datePublished">2020-05-16</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2020/05/16/linux/linux_awk_sed/">linux-awk\sed 示例</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h5 id="linux-awk-sed-示例"><a href="#linux-awk-sed-示例" class="headerlink" title="linux-awk\sed 示例"></a>linux-awk\sed 示例</h5><ul>
<li>统计ip出现的次数<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">awk '&#123;print $1&#125;' nginx.log | sort | uniq -c | sort -nr | head -n 10</span><br><span class="line"></span><br><span class="line">awk '&#123;print $1&#125;' nginx.log | sort | uniq -c | sort -nr | head -10</span><br><span class="line"></span><br><span class="line">说明：</span><br><span class="line">sort 排序 </span><br><span class="line">uniq -c 合并相邻相同的并统计</span><br><span class="line">sort 排序 -n 按照数值排序  -r反序</span><br><span class="line">head 取值多少</span><br></pre></td></tr></table></figure>
</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 匹配 错误日志：</span></span><br><span class="line">awk '$9~/500|404/&#123;print $0&#125;' nginx.log</span><br></pre></td></tr></table></figure>
<ul>
<li><p>访问量最高的url</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">awk '&#123;print $7&#125;' nginx.log|</span><br><span class="line">sed -e 's/\?.*//g' \</span><br><span class="line">	-e 's/\/avatar\/[0-9]*/\/avatar\/int/g' \</span><br><span class="line">	-e 's/\topcs\/[0-9]*/\/topics\/int/g' \</span><br><span class="line">	-e 's/\/replies\/[0-9]*/\/replies\/int/g' \</span><br><span class="line">	-e 's/\/[0-9a-z\-]*\.png/\id.png/g' \</span><br><span class="line">	-e 's/\/[0-9a-z\-]*\.jpg/\/id.jpg/g' \</span><br><span class="line">	-e 's/\/[0-9a-z\-]*\.jepg/\/id.jepg/g' \</span><br><span class="line">	-e 's/\/[0-9a-z\-]*\.gif/\/id.gif/g' |</span><br><span class="line">sort | uniq -c | sort -nr</span><br></pre></td></tr></table></figure>
</li>
<li><p>nginx.log</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><span class="line">223.104.7.59 - - [05/Dec/2018:00:00:01 +0000] &quot;GET /topics/17112 HTTP/2.0&quot; 200 9874 &quot;https://www.googleapis.com/auth/chrome-content-suggestions&quot; &quot;Mozilla/5.0 (iPhone; CPU iPhone OS 12_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/70.0.3538.75 Mobile/15E148 Safari/605.1&quot; 0.040 0.040 .</span><br><span class="line">123.125.71.60 - - [05/Dec/2018:00:00:02 +0000] &quot;GET /yuanyibo/topics?locale=en HTTP/1.1&quot; 200 12164 &quot;-&quot; &quot;Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)&quot; 0.032 0.032 .</span><br><span class="line">141.8.142.131 - - [05/Dec/2018:00:00:02 +0000] &quot;GET /topics?page=63 HTTP/1.1&quot; 200 16739 &quot;-&quot; &quot;Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots)&quot; 0.120 0.120 .</span><br><span class="line">139.180.131.123 - - [05/Dec/2018:00:00:01 +0000] &quot;GET /cable HTTP/1.1&quot; 101 15073 &quot;-&quot; &quot;Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36&quot; 592.015 592.015 .</span><br><span class="line">40.77.167.60 - - [05/Dec/2018:00:00:03 +0000] &quot;GET /hehe123 HTTP/1.1&quot; 200 3494 &quot;-&quot; &quot;Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)&quot; 0.033 0.033 .</span><br><span class="line">204.141.42.226 - - [05/Dec/2018:00:00:04 +0000] &quot;GET / HTTP/1.1&quot; 301 5 &quot;-&quot; &quot;Site24x7&quot; 0.002 0.002 .</span><br><span class="line">40.77.167.60 - - [05/Dec/2018:00:00:04 +0000] &quot;GET /uploads/user/avatar/11094.jpg!xs HTTP/1.1&quot; 200 1499 &quot;-&quot; &quot;Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)&quot; 0.011 0.011 .</span><br><span class="line">127.0.0.1 - - [05/Dec/2018:00:00:04 +0000] &quot;GET /_img/uploads/user/avatar/11094.jpg!xs HTTP/1.0&quot; 200 1499 &quot;-&quot; &quot;Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)&quot; 0.011 - .</span><br><span class="line">139.180.131.123 - - [05/Dec/2018:00:00:01 +0000] &quot;GET /cable HTTP/1.1&quot; 101 7549 &quot;-&quot; &quot;Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36&quot; 587.602 587.602 .</span><br><span class="line">117.136.39.87 - - [05/Dec/2018:00:00:01 +0000] &quot;GET /uploads/user/avatar/12759.jpg!large HTTP/1.1&quot; 200 1866441 &quot;-&quot; &quot;okhttp/3.2.0&quot; 3.910 1.336 .</span><br><span class="line">121.15.166.147 - - [05/Dec/2018:00:00:07 +0000] &quot;GET /cable HTTP/1.1&quot; 101 335037 &quot;-&quot; &quot;Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36&quot; 26471.138 26471.138 .</span><br><span class="line">219.142.131.122 - - [05/Dec/2018:00:00:07 +0000] &quot;GET /cable HTTP/1.1&quot; 101 361523 &quot;-&quot; &quot;Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.103 Safari/537.36 Vivaldi/2.1.1337.47&quot; 28563.286 28563.286 .</span><br><span class="line">61.132.54.2 - - [05/Dec/2018:00:00:07 +0000] &quot;GET /cable HTTP/1.1&quot; 101 380979 &quot;-&quot; &quot;Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.89 Safari/537.36&quot; 30102.676 30102.676 .</span><br><span class="line">103.75.152.102 - - [05/Dec/2018:00:00:07 +0000] &quot;GET /cable HTTP/1.1&quot; 101 424907 &quot;-&quot; &quot;Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36&quot; 33572.810 33572.810 .</span><br><span class="line">222.66.96.129 - - [05/Dec/2018:00:00:07 +0000] &quot;GET /cable HTTP/1.1&quot; 101 424907 &quot;-&quot; &quot;Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36&quot; 33573.471 33573.471 .</span><br><span class="line">180.168.166.28 - - [05/Dec/2018:00:00:07 +0000] &quot;GET /cable HTTP/1.1&quot; 101 424907 &quot;-&quot; &quot;Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36&quot; 33573.628 33573.628 .</span><br><span class="line">114.94.126.62 - - [05/Dec/2018:00:00:07 +0000] &quot;GET /cable HTTP/1.1&quot; 101 510141 &quot;-&quot; &quot;Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.62 Safari/537.36&quot; 40313.333 40313.333 .</span><br><span class="line">61.135.169.90 - - [05/Dec/2018:00:00:07 +0000] &quot;GET /cable HTTP/1.1&quot; 101 531953 &quot;-&quot; &quot;Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36&quot; 42038.134 42038.134 .</span><br><span class="line">120.36.255.107 - - [05/Dec/2018:00:00:07 +0000] &quot;GET /cable HTTP/1.1&quot; 101 580604 &quot;-&quot; &quot;Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36&quot; 45876.266 45876.266 .</span><br><span class="line">14.21.33.152 - - [05/Dec/2018:00:00:07 +0000] &quot;GET /cable HTTP/1.1&quot; 101 580631 &quot;-&quot; &quot;Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36&quot; 45884.878 45884.878 .</span><br><span class="line">103.218.216.115 - - [05/Dec/2018:00:00:07 +0000] &quot;GET /cable HTTP/1.1&quot; 101 593019 &quot;-&quot; &quot;Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36&quot; 46865.329 46865.329 .</span><br><span class="line">124.200.99.162 - - [05/Dec/2018:00:00:07 +0000] &quot;GET /cable HTTP/1.1&quot; 101 593019 &quot;-&quot; &quot;Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36&quot; 46865.485 46865.485 .</span><br><span class="line">101.95.128.162 - - [05/Dec/2018:00:00:07 +0000] &quot;GET /cable HTTP/1.1&quot; 101 593106 &quot;-&quot; &quot;Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36&quot; 46865.503 46865.503 .</span><br><span class="line">45.120.31.9 - - [05/Dec/2018:00:00:07 +0000] &quot;GET /cable HTTP/1.1&quot; 101 636757 &quot;-&quot; &quot;Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:63.0) Gecko/20100101 Firefox/63.0&quot; 50322.346 50322.346 .</span><br><span class="line">125.46.24.19 - - [05/Dec/2018:00:00:07 +0000] &quot;GET /cable HTTP/1.1&quot; 101 941 &quot;-&quot; &quot;Mozilla/5.0 (Windows NT 6.1; WOW64; rv:63.0) Gecko/20100101 Firefox/63.0&quot; 65.038 65.038 .</span><br><span class="line">220.178.67.222 - - [05/Dec/2018:00:00:07 +0000] &quot;GET /cable HTTP/1.1&quot; 101 14089 &quot;-&quot; &quot;Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36 QQBrowser/4.4.116.400&quot; 1104.968 1104.968 .</span><br><span class="line">122.225.218.44 - - [05/Dec/2018:00:00:07 +0000] &quot;GET /cable HTTP/1.1&quot; 101 18725 &quot;-&quot; &quot;Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 Safari/537.36&quot; 1471.999 1471.999 .</span><br><span class="line">206.16.17.150 - - [05/Dec/2018:00:00:07 +0000] &quot;GET /cable HTTP/1.1&quot; 101 64135 &quot;-&quot; &quot;Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36&quot; 5061.106 5061.106 .</span><br><span class="line">202.189.3.9 - - [05/Dec/2018:00:00:07 +0000] &quot;GET /cable HTTP/1.1&quot; 101 80703 &quot;-&quot; &quot;Mozilla/5.0 (Windows NT 6.1; WOW64; rv:63.0) Gecko/20100101 Firefox/63.0&quot; 6370.541 6370.541 .</span><br><span class="line">14.17.22.35 - - [05/Dec/2018:00:00:07 +0000] &quot;GET /cable HTTP/1.1&quot; 101 91115 &quot;-&quot; &quot;Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.84 Safari/537.36&quot; 7190.962 7190.962 .</span><br><span class="line">114.80.11.236 - - [05/Dec/2018:00:00:07 +0000] &quot;GET /cable HTTP/1.1&quot; 101 169319 &quot;-&quot; &quot;Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36&quot; 13372.959 13372.959 .</span><br><span class="line">221.226.97.96 - - [05/Dec/2018:00:00:07 +0000] &quot;GET /cable HTTP/1.1&quot; 101 182087 &quot;-&quot; &quot;Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36&quot; 14383.058 14383.058 .</span><br><span class="line">115.236.48.202 - - [05/Dec/2018:00:00:07 +0000] &quot;GET /cable HTTP/1.1&quot; 101 215196 &quot;-&quot; &quot;Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.26 Safari/537.36 Core/1.63.6776.400 QQBrowser/10.3.2601.400&quot; 16992.246 16992.246 .</span><br><span class="line">153.37.218.54 - - [05/Dec/2018:00:00:07 +0000] &quot;GET /cable HTTP/1.1&quot; 101 261583 &quot;-&quot; &quot;Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36&quot; 20663.731 20663.731 .</span><br><span class="line">171.43.191.215 - - [05/Dec/2018:00:00:07 +0000] &quot;GET /cable HTTP/1.1&quot; 101 273021 &quot;-&quot; &quot;Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36&quot; 21568.749 21568.749 .</span><br><span class="line">136.243.151.90 - - [05/Dec/2018:00:00:07 +0000] &quot;GET /topics/16689/replies/124751/edit HTTP/1.1&quot; 302 100 &quot;-&quot; &quot;Mozilla/5.0 (compatible; BLEXBot/1.0; +http://webmeup-crawler.com/)&quot; 0.009 0.009 .</span><br><span class="line">136.243.151.90 - - [05/Dec/2018:00:00:07 +0000] &quot;GET / HTTP/1.1&quot; 200 10085 &quot;-&quot; &quot;Mozilla/5.0 (compatible; BLEXBot/1.0; +http://webmeup-crawler.com/)&quot; 0.071 0.071 .</span><br><span class="line">117.136.39.87 - - [05/Dec/2018:00:00:07 +0000] &quot;GET /oauth/authorize?response_type=code&amp;client_id=6dbe4244&amp;state=E3ZYKC1T6H2yP4z&amp;redirect_uri=urn:ietf:wg:oauth:2.0:oob HTTP/1.1&quot; 302 115 &quot;-&quot; &quot;Mozilla/5.0 (Linux; Android 8.1.0; COL-AL10 Build/HUAWEICOL-AL10; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/68.0.3440.91 Mobile Safari/537.36&quot; 0.004 0.004 .</span><br><span class="line">115.236.50.18 - - [05/Dec/2018:00:00:07 +0000] &quot;GET /cable HTTP/1.1&quot; 404 45 &quot;-&quot; &quot;Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36&quot; 0.004 0.004 .</span><br><span class="line">123.121.16.2 - - [05/Dec/2018:00:00:07 +0000] &quot;GET /cable HTTP/1.1&quot; 101 5349 &quot;-&quot; &quot;Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:56.0) Gecko/20100101 Firefox/56.0&quot; 415.053 415.053 .</span><br></pre></td></tr></table></figure></li>
</ul>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2020/05/16/linux/linux_awk_sed/" data-id="ckcc5iwoq007mq4uwal4qaoer" class="article-share-link">Teilen</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/linux/">linux</a></li></ul>

    </footer>
  </div>
  
</article>


  
    <article id="post-linux/linux_bash" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2020/04/11/linux/linux_bash/" class="article-date">
  <time datetime="2020-04-11T07:02:19.000Z" itemprop="datePublished">2020-04-11</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2020/04/11/linux/linux_bash/">linux—bash</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h5 id="bash："><a href="#bash：" class="headerlink" title="bash："></a>bash：</h5><ul>
<li>变量</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">a=1</span><br><span class="line">b=&quot;hello world&quot;</span><br><span class="line">c=&quot;hello world&quot;</span><br></pre></td></tr></table></figure>
<p>❖ = 左右不要有空格<br>❖ 如果内容有空格，需要使⽤单引号或者双引号<br>❖ 双引号⽀持转义  $开头的变量会被⾃动替换</p>
<ul>
<li>变量使用<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">echo $a </span><br><span class="line">echo $&#123;b&#125;</span><br><span class="line">echo &quot;$c&quot;</span><br></pre></td></tr></table></figure>
</li>
</ul>
<p>❖ 使⽤$var  或 ${var}来访问变量。后者更为严谨。$var_x ${var}_x 是不同的。<br>❖ 变量不需要定义也可以使⽤。引⽤未定义的变量，默认为空值。</p>
<ul>
<li>预定义变量</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">echo $PWD </span><br><span class="line">echo $USER </span><br><span class="line">echo $HOME </span><br><span class="line">echo ~ </span><br><span class="line">echo $PATH </span><br><span class="line">echo $RANDOM</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">❖ 双引号⽤于括起⼀段字符串值，⽀持$var形式的变量替换 </span><br><span class="line">❖ 单引号也表⽰其内容是字符串值，不⽀持转义 </span><br><span class="line">❖ &#123;1..10&#125; 等价于  seq 1 10，表⽰1到10 </span><br><span class="line">❖ seq 1 3 10 表⽰⽣成⼀个1到10，步进为3</span><br></pre></td></tr></table></figure>
<ul>
<li>变量类型</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">字符串 a=&quot;xx&quot; </span><br><span class="line">数字 i=1314 </span><br><span class="line">布尔 true  false </span><br><span class="line">数组 array=(a b c) </span><br><span class="line">函数 foo() &#123; echo hello world &#125;</span><br></pre></td></tr></table></figure>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2020/04/11/linux/linux_bash/" data-id="ckcc5iwop007kq4uwu5wh35wy" class="article-share-link">Teilen</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/linux/">linux</a></li></ul>

    </footer>
  </div>
  
</article>


  
    <article id="post-hello-world" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2020/03/29/hello-world/" class="article-date">
  <time datetime="2020-03-29T11:01:59.531Z" itemprop="datePublished">2020-03-29</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2020/03/29/hello-world/">Hello World</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <p>Welcome to <a href="https://hexo.io/" target="_blank" rel="noopener">Hexo</a>! This is your very first post. Check <a href="https://hexo.io/docs/" target="_blank" rel="noopener">documentation</a> for more info. If you get any problems when using Hexo, you can find the answer in <a href="https://hexo.io/docs/troubleshooting.html" target="_blank" rel="noopener">troubleshooting</a> or you can ask me on <a href="https://github.com/hexojs/hexo/issues" target="_blank" rel="noopener">GitHub</a>.</p>
<h2 id="Quick-Start"><a href="#Quick-Start" class="headerlink" title="Quick Start"></a>Quick Start</h2><h3 id="Create-a-new-post"><a href="#Create-a-new-post" class="headerlink" title="Create a new post"></a>Create a new post</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo new <span class="string">"My New Post"</span></span><br></pre></td></tr></table></figure>
<p>More info: <a href="https://hexo.io/docs/writing.html" target="_blank" rel="noopener">Writing</a></p>
<h3 id="Run-server"><a href="#Run-server" class="headerlink" title="Run server"></a>Run server</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo server</span><br></pre></td></tr></table></figure>
<p>More info: <a href="https://hexo.io/docs/server.html" target="_blank" rel="noopener">Server</a></p>
<h3 id="Generate-static-files"><a href="#Generate-static-files" class="headerlink" title="Generate static files"></a>Generate static files</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo generate</span><br></pre></td></tr></table></figure>
<p>More info: <a href="https://hexo.io/docs/generating.html" target="_blank" rel="noopener">Generating</a></p>
<h3 id="Deploy-to-remote-sites"><a href="#Deploy-to-remote-sites" class="headerlink" title="Deploy to remote sites"></a>Deploy to remote sites</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo deploy</span><br></pre></td></tr></table></figure>
<p>More info: <a href="https://hexo.io/docs/deployment.html" target="_blank" rel="noopener">Deployment</a></p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2020/03/29/hello-world/" data-id="ckcc5iwkc001zq4uwpzbay314" class="article-share-link">Teilen</a>
      
      
    </footer>
  </div>
  
</article>


  
    <article id="post-go基础" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2020/03/16/go基础/" class="article-date">
  <time datetime="2020-03-16T11:20:35.000Z" itemprop="datePublished">2020-03-16</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2020/03/16/go基础/">go基础知识</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h1 id="go基础知识"><a href="#go基础知识" class="headerlink" title="go基础知识"></a>go基础知识</h1><figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> main</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> <span class="string">"fmt"</span></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">main</span><span class="params">()</span></span> &#123;</span><br><span class="line"></span><br><span class="line">   fmt.Println(<span class="string">"Hello, World!"</span>)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<ul>
<li>每个Go应用程序都包含一个名为 main 的包</li>
<li>“{“ 不能在单独的一行</li>
<li>import的包如果下面没有使用到的话会报错;变量同是如此</li>
</ul>
<h3 id="变量声明"><a href="#变量声明" class="headerlink" title="变量声明"></a>变量声明</h3><ul>
<li>在 Go 语言中，采用的是后置类型的声明方式    <figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&lt;命名&gt; &lt;类型&gt;</span><br></pre></td></tr></table></figure>
</li>
</ul>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">x <span class="keyword">int</span> <span class="comment">// 定义 x 为整数类型</span></span><br></pre></td></tr></table></figure>
<ul>
<li><p>在 Go 语言中通常我们使用关键字 var 来声明变量</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> x <span class="keyword">int</span> <span class="comment">// 表示声明一个名为 x 的整数变量</span></span><br><span class="line"><span class="keyword">var</span> b <span class="keyword">int</span> = <span class="number">1</span> <span class="comment">// 表示声明一个名为 b 的整数变量，并且附上初始值为 1</span></span><br><span class="line"><span class="keyword">var</span> b = <span class="number">1</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>可同时声明</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> (</span><br><span class="line">    a, b <span class="keyword">int</span>  <span class="comment">// 同时声明 a, b 的整数</span></span><br><span class="line">    c <span class="keyword">float64</span></span><br><span class="line">)</span><br></pre></td></tr></table></figure>
</li>
<li><p><strong>简短声明方式</strong></p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">a := <span class="number">1</span> <span class="comment">// 声明 a 为 1 的整数</span></span><br><span class="line">b := <span class="keyword">int64</span>(<span class="number">1</span>)  <span class="comment">// 声明 b 为 1 的 64 位整数</span></span><br></pre></td></tr></table></figure>
</li>
</ul>
<h3 id="常量定义"><a href="#常量定义" class="headerlink" title="常量定义"></a>常量定义</h3><ul>
<li>常量指定的值类型主要有三类： 布尔，数字，字符串， 其中数字类型包含（rune, integer, floating-point, complex), 它们都属于基本数据类型。</li>
<li>不能使用 :=<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> a = <span class="number">64</span> <span class="comment">// 定义常量值为 64 的值</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> (</span><br><span class="line">  b = <span class="number">4</span></span><br><span class="line">  c = <span class="number">0.1</span></span><br><span class="line">)</span><br></pre></td></tr></table></figure>
</li>
</ul>
<h3 id="Go-语言中的基本数据类型"><a href="#Go-语言中的基本数据类型" class="headerlink" title="Go 语言中的基本数据类型"></a>Go 语言中的基本数据类型</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">bool      the set of boolean (true, false)</span><br><span class="line"></span><br><span class="line">uint8      the set of all unsigned  8-bit integers (0 to 255)</span><br><span class="line">uint16      the set of all unsigned 16-bit integers (0 to 65535)</span><br><span class="line">uint32      the set of all unsigned 32-bit integers (0 to 4294967295)</span><br><span class="line">uint64      the set of all unsigned 64-bit integers (0 to 18446744073709551615)</span><br><span class="line"></span><br><span class="line">int8      the set of all signed  8-bit integers (-128 to 127)</span><br><span class="line">int16      the set of all signed 16-bit integers (-32768 to 32767)</span><br><span class="line">int32      the set of all signed 32-bit integers (-2147483648 to 2147483647)</span><br><span class="line">int64      the set of all signed 64-bit integers (-9223372036854775808 to 9223372036854775807)</span><br><span class="line"></span><br><span class="line">float32      the set of all IEEE-754 32-bit floating-point numbers</span><br><span class="line">float64      the set of all IEEE-754 64-bit floating-point numbers</span><br><span class="line"></span><br><span class="line">complex64      the set of all complex numbers with float32 real and imaginary parts</span><br><span class="line">complex128      the set of all complex numbers with float64 real and imaginary parts</span><br><span class="line"></span><br><span class="line">byte      alias for uint8</span><br><span class="line">rune      alias for int32</span><br><span class="line">uint      either 32 or 64 bits</span><br><span class="line">int      same size as uint</span><br><span class="line">uintptr      an unsigned integer large enough to store the uninterpreted bits of a pointer value</span><br><span class="line"></span><br><span class="line">string      the set of string value (eg: "hi")</span><br></pre></td></tr></table></figure>
<ul>
<li><p>布尔类型</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> a <span class="keyword">bool</span></span><br><span class="line"><span class="keyword">var</span> a = <span class="literal">true</span></span><br><span class="line">a := <span class="literal">true</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> a = <span class="literal">true</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>数字类型</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> (</span><br><span class="line">  a <span class="keyword">uint8</span> = <span class="number">1</span></span><br><span class="line">  b <span class="keyword">int8</span> = <span class="number">1</span></span><br><span class="line">)</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> (</span><br><span class="line">    c <span class="keyword">int</span> = <span class="number">64</span></span><br><span class="line">)</span><br></pre></td></tr></table></figure>
</li>
<li><p>字符串</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> a = <span class="string">"hello"</span> <span class="comment">//单行字符串</span></span><br><span class="line"><span class="keyword">var</span> c = <span class="string">"\""</span> <span class="comment">// 转义符</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> b = <span class="string">`hello`</span> <span class="comment">//原样输出</span></span><br><span class="line"><span class="keyword">var</span> d = <span class="string">`line3  //多行输出</span></span><br><span class="line"><span class="string">line1</span></span><br><span class="line"><span class="string">line2</span></span><br><span class="line"><span class="string">`</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> str = <span class="string">"hello, 世界"</span></span><br><span class="line"></span><br><span class="line">b := str[<span class="number">0</span>]  <span class="comment">//b is a uint8 type, like byte</span></span><br><span class="line">fmt.Println(b)  <span class="comment">// 104</span></span><br><span class="line">fmt.Println(<span class="keyword">string</span>(b)) <span class="comment">// h</span></span><br><span class="line"></span><br><span class="line">fmt.Println(<span class="built_in">len</span>(str)) <span class="comment">//12, 查看字符串有多少个字节</span></span><br><span class="line">fmt.Println(<span class="built_in">len</span>([]<span class="keyword">rune</span>(str))) <span class="comment">// 8 查看有多少个字符</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>特殊类型</p>
</li>
<li>byte，uint8 别名，用于表示二进制数据的 bytes</li>
<li>rune，int32 别名, 用于表示一个符号<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> str = <span class="string">"hello, 世界"</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span> _, char := <span class="keyword">range</span> str &#123;</span><br><span class="line">  fmt.Printf(<span class="string">"%T"</span>, char)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
</ul>
<h3 id="运算符"><a href="#运算符" class="headerlink" title="运算符"></a>运算符</h3><ul>
<li>位运算</li>
</ul>
<ol>
<li><p>按位与&amp;： T（true）替换为 1， F（false）替换为 0</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">1 &amp; 1 -&gt; 1</span><br><span class="line">1 &amp; 0 -&gt; 0</span><br><span class="line">0 &amp; 1 -&gt; 0</span><br><span class="line">0 &amp; 0 -&gt; 0</span><br></pre></td></tr></table></figure>
</li>
<li><p>按位或 |： T（true）替换为 1， F（false）替换为 0</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">1 | 1 -&gt; 1</span><br><span class="line">1 | 0 -&gt; 1</span><br><span class="line">0 | 1 -&gt; 1</span><br><span class="line">0 | 0 -&gt; 0</span><br></pre></td></tr></table></figure>
</li>
<li><p>按位异或 ^： 相同为0，不同为1</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">1 ^ 1 -&gt; 0</span><br><span class="line">1 ^ 0 -&gt; 1</span><br><span class="line">0 ^ 1 -&gt; 1</span><br><span class="line">0 ^ 0 -&gt; 0</span><br></pre></td></tr></table></figure>
</li>
</ol>
<ul>
<li>逻辑运算符</li>
</ul>
<ol>
<li><p>非运算符：!</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">!T -&gt; false</span><br><span class="line">!F -&gt; true</span><br></pre></td></tr></table></figure>
</li>
<li><p>和运算符：&amp;&amp;</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">T &amp;&amp; T -&gt; true</span><br><span class="line">T &amp;&amp; F -&gt; false</span><br><span class="line">F &amp;&amp; T -&gt; false</span><br><span class="line">F &amp;&amp; F -&gt; false</span><br></pre></td></tr></table></figure>
</li>
<li><p>或运算符：||</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">T || T -&gt; true</span><br><span class="line">T || F -&gt; true</span><br><span class="line">F || T -&gt; true</span><br><span class="line">F || F -&gt; fals</span><br></pre></td></tr></table></figure>
</li>
<li></li>
</ol>
<ul>
<li>算术运算符</li>
</ul>
<ol>
<li>常见可用于整数和浮点数的二元运算符有 +、-、* 和 /。</li>
<li>/ 对与整数运算而言，结果依旧为整数，例如：9 / 4 -&gt; 2。</li>
<li>取余运算符只能作用于整数：9 % 4 -&gt; 1。</li>
</ol>
<p>可以将语句 b = b + a 简写为 b+=a，同样的写法也可用于 -=、*=、/=、%=<br>对于整数和浮点数，你可以使用一元运算符 ++（递增）和 –（递减），但只能用于后缀：<br><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">i++ -&gt; i += 1 -&gt; i = i + 1</span><br><span class="line">i-- -&gt; i -= 1 -&gt; i = i - 1</span><br></pre></td></tr></table></figure></p>
<p>带有 ++ 和 – 的只能作为语句，而非表达式，因此 n = i++ 这种写法是无效的，其它像 f(i++) 或者 a[i]=b[i++] 这些可以用于 C、C++ 和 Java 中的写法在 Go 中也是不允许的。</p>
<ul>
<li>运算符与优先级 ↑<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">优先级     运算符</span><br><span class="line"> 7         ^ !</span><br><span class="line"> 6         * / % &lt;&lt; &gt;&gt; &amp; &amp;^</span><br><span class="line"> 5         + - | ^</span><br><span class="line"> 4         == != &lt; &lt;= &gt;= &gt;</span><br><span class="line"> 3         &lt;-</span><br><span class="line"> 2         &amp;&amp;</span><br><span class="line"> 1         ||</span><br></pre></td></tr></table></figure>
</li>
</ul>
<h3 id="时间和日期"><a href="#时间和日期" class="headerlink" title="时间和日期"></a>时间和日期</h3><figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> main</span><br><span class="line"><span class="keyword">import</span> (</span><br><span class="line">    <span class="string">"fmt"</span></span><br><span class="line">    <span class="string">"time"</span></span><br><span class="line">)</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> week time.Duration</span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">main</span><span class="params">()</span></span> &#123;</span><br><span class="line">    t := time.Now()</span><br><span class="line">    fmt.Println(t) <span class="comment">// e.g. Wed Dec 21 09:52:14 +0100 RST 2011</span></span><br><span class="line">    fmt.Printf(<span class="string">"%02d.%02d.%4d\n"</span>, t.Day(), t.Month(), t.Year())</span><br><span class="line">    <span class="comment">// 21.12.2011</span></span><br><span class="line">    t = time.Now().UTC()</span><br><span class="line">    fmt.Println(t) <span class="comment">// Wed Dec 21 08:52:14 +0000 UTC 2011</span></span><br><span class="line">    fmt.Println(time.Now()) <span class="comment">// Wed Dec 21 09:52:14 +0100 RST 2011</span></span><br><span class="line">    <span class="comment">// calculating times:</span></span><br><span class="line">    week = <span class="number">60</span> * <span class="number">60</span> * <span class="number">24</span> * <span class="number">7</span> * <span class="number">1e9</span> <span class="comment">// must be in nanosec</span></span><br><span class="line">    week_from_now := t.Add(week)</span><br><span class="line">    fmt.Println(week_from_now) <span class="comment">// Wed Dec 28 08:52:14 +0000 UTC 2011</span></span><br><span class="line">    <span class="comment">// formatting times:</span></span><br><span class="line">    fmt.Println(t.Format(time.RFC822)) <span class="comment">// 21 Dec 11 0852 UTC</span></span><br><span class="line">    fmt.Println(t.Format(time.ANSIC)) <span class="comment">// Wed Dec 21 08:56:34 2011</span></span><br><span class="line">    fmt.Println(t.Format(<span class="string">"02 Jan 2006 15:04"</span>)) <span class="comment">// 21 Dec 2011 08:52</span></span><br><span class="line">    s := t.Format(<span class="string">"20060102"</span>)</span><br><span class="line">    fmt.Println(t, <span class="string">"=&gt;"</span>, s)</span><br><span class="line">    <span class="comment">// Wed Dec 21 08:52:14 +0000 UTC 2011 =&gt; 20111221</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2020/03/16/go基础/" data-id="ckcc5iwk3001pq4uw0351wffw" class="article-share-link">Teilen</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/go/">go</a></li></ul>

    </footer>
  </div>
  
</article>


  
    <article id="post-go安装和配置" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2020/03/16/go安装和配置/" class="article-date">
  <time datetime="2020-03-16T11:20:35.000Z" itemprop="datePublished">2020-03-16</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2020/03/16/go安装和配置/">go安装和配置</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h1 id="go安装和配置"><a href="#go安装和配置" class="headerlink" title="go安装和配置"></a>go安装和配置</h1><ul>
<li>下载地址1：<a href="https://golang.org/dl/" target="_blank" rel="noopener">https://golang.org/dl/</a>  </li>
<li>下载地址2：<a href="https://golang.google.cn/dl/" target="_blank" rel="noopener">https://golang.google.cn/dl/</a>  </li>
<li>配置go环境变量</li>
<li>检查go安装  <figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">go version</span><br></pre></td></tr></table></figure></li>
</ul>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2020/03/16/go安装和配置/" data-id="ckcc5iwk8001uq4uw085azrcx" class="article-share-link">Teilen</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/go/">go</a></li></ul>

    </footer>
  </div>
  
</article>


  
    <article id="post-go控制结构" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2020/03/16/go控制结构/" class="article-date">
  <time datetime="2020-03-16T11:20:35.000Z" itemprop="datePublished">2020-03-16</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2020/03/16/go控制结构/">go控制结构</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h1 id="go控制结构"><a href="#go控制结构" class="headerlink" title="go控制结构"></a>go控制结构</h1><h3 id="if-else"><a href="#if-else" class="headerlink" title="if-else"></a>if-else</h3><ul>
<li>go if去除了条件的（）<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> main</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> <span class="string">"fmt"</span></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">main</span><span class="params">()</span></span> &#123;</span><br><span class="line">    <span class="keyword">var</span> first <span class="keyword">int</span> = <span class="number">10</span></span><br><span class="line">    <span class="keyword">var</span> cond <span class="keyword">int</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span> first &lt;= <span class="number">0</span> &#123;</span><br><span class="line"></span><br><span class="line">        fmt.Printf(<span class="string">"first is less than or equal to 0\n"</span>)</span><br><span class="line">    &#125; <span class="keyword">else</span> <span class="keyword">if</span> first &gt; <span class="number">0</span> &amp;&amp; first &lt; <span class="number">5</span> &#123;</span><br><span class="line"></span><br><span class="line">        fmt.Printf(<span class="string">"first is between 0 and 5\n"</span>)</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line"></span><br><span class="line">        fmt.Printf(<span class="string">"first is 5 or greater\n"</span>)</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">if</span> cond = <span class="number">5</span>; cond &gt; <span class="number">10</span> &#123;</span><br><span class="line"></span><br><span class="line">        fmt.Printf(<span class="string">"cond is greater than 10\n"</span>)</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line"></span><br><span class="line">        fmt.Printf(<span class="string">"cond is not greater than 10\n"</span>)</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
</ul>
<h3 id="switch-结构"><a href="#switch-结构" class="headerlink" title="switch 结构"></a>switch 结构</h3><figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> main</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> <span class="string">"fmt"</span></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">main</span><span class="params">()</span></span> &#123;</span><br><span class="line">    <span class="keyword">var</span> num1 <span class="keyword">int</span> = <span class="number">100</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">switch</span> num1 &#123;</span><br><span class="line">    <span class="keyword">case</span> <span class="number">98</span>, <span class="number">99</span>:</span><br><span class="line">        fmt.Println(<span class="string">"It's equal to 98"</span>)</span><br><span class="line">    <span class="keyword">case</span> <span class="number">100</span>: </span><br><span class="line">        fmt.Println(<span class="string">"It's equal to 100"</span>)</span><br><span class="line">    <span class="keyword">default</span>:</span><br><span class="line">        fmt.Println(<span class="string">"It's not equal to 98 or 100"</span>)</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">out: It's equal to 100</span><br></pre></td></tr></table></figure>
<h3 id="for"><a href="#for" class="headerlink" title="for"></a>for</h3><figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> main</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> <span class="string">"fmt"</span></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">main</span><span class="params">()</span></span> &#123;</span><br><span class="line">    <span class="keyword">for</span> i := <span class="number">0</span>; i &lt; <span class="number">5</span>; i++ &#123;</span><br><span class="line">        fmt.Printf(<span class="string">"This is the %d iteration\n"</span>, i)</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<ul>
<li>for 结构的第二种形式是没有头部的条件判断迭代（类似其它语言中的 while 循环），基本形式为：for 条件语句 {}。<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> main</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> <span class="string">"fmt"</span></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">main</span><span class="params">()</span></span> &#123;</span><br><span class="line">    <span class="keyword">var</span> i <span class="keyword">int</span> = <span class="number">5</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">for</span> i &gt;= <span class="number">0</span> &#123;</span><br><span class="line">        i = i - <span class="number">1</span></span><br><span class="line">        fmt.Printf(<span class="string">"The variable i is now: %d\n"</span>, i)</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">The variable i is now: 4</span><br><span class="line">The variable i is now: 3</span><br><span class="line">The variable i is now: 2</span><br><span class="line">The variable i is now: 1</span><br><span class="line">The variable i is now: 0</span><br><span class="line">The variable i is now: -1</span><br></pre></td></tr></table></figure>
<h3 id="break-continue"><a href="#break-continue" class="headerlink" title="break continue"></a>break continue</h3><figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> main</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">main</span><span class="params">()</span></span> &#123;</span><br><span class="line">    <span class="keyword">for</span> i:=<span class="number">0</span>; i&lt;<span class="number">3</span>; i++ &#123;</span><br><span class="line">        <span class="keyword">for</span> j:=<span class="number">0</span>; j&lt;<span class="number">10</span>; j++ &#123;</span><br><span class="line">            <span class="keyword">if</span> j&gt;<span class="number">5</span> &#123;</span><br><span class="line">                <span class="keyword">break</span>   </span><br><span class="line">            &#125;</span><br><span class="line">            <span class="built_in">print</span>(j)</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="built_in">print</span>(<span class="string">"  "</span>)</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">012345 012345 012345</span><br></pre></td></tr></table></figure>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> main</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">main</span><span class="params">()</span></span> &#123;</span><br><span class="line">    <span class="keyword">for</span> i := <span class="number">0</span>; i &lt; <span class="number">10</span>; i++ &#123;</span><br><span class="line">        <span class="keyword">if</span> i == <span class="number">5</span> &#123;</span><br><span class="line">            <span class="keyword">continue</span></span><br><span class="line">        &#125;</span><br><span class="line">        <span class="built_in">print</span>(i)</span><br><span class="line">        <span class="built_in">print</span>(<span class="string">" "</span>)</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">0 1 2 3 4 6 7 8 9</span><br></pre></td></tr></table></figure>
      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2020/03/16/go控制结构/" data-id="ckcc5iwk9001xq4uwi2gt1v1d" class="article-share-link">Teilen</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/go/">go</a></li></ul>

    </footer>
  </div>
  
</article>


  
    <article id="post-linux/linux_三剑客" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2020/01/01/linux/linux_三剑客/" class="article-date">
  <time datetime="2020-01-01T07:09:12.000Z" itemprop="datePublished">2020-01-01</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2020/01/01/linux/linux_三剑客/">linux—三剑客</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h4 id="linux—三剑客"><a href="#linux—三剑客" class="headerlink" title="linux—三剑客"></a>linux—三剑客</h4><h5 id="grep"><a href="#grep" class="headerlink" title="grep"></a>grep</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">❖ grep pattern ﬁle </span><br><span class="line">❖ grep -i pattern ﬁle 忽略⼤⼩写 </span><br><span class="line">❖ grep -v pattern ﬁle 不显⽰匹配的⾏ </span><br><span class="line">❖ grep -o pattern ﬁle 把每个匹配的内容⽤独⽴的⾏显⽰ </span><br><span class="line">❖ grep -E pattern ﬁle 使⽤扩展正则表达式 </span><br><span class="line">❖ grep -A -B -C pattern ﬁle 打印命中数据的上下⽂ </span><br><span class="line">❖ grep pattern -r dir/ 递归搜索</span><br></pre></td></tr></table></figure>
<ul>
<li>基本表达式<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">❖ 基本表达式（BRE） </span><br><span class="line">    ❖ ^ 开头 $结尾 </span><br><span class="line">    ❖ [a-z]  [0-9] 区间，如果开头带有^表⽰不能匹配区间内的元素 </span><br><span class="line">    ❖ * 0个或多个 </span><br><span class="line">    ❖ . 表⽰任意字符 </span><br><span class="line">❖ 基本正则（BRE）与扩展正则的区别（ERE） </span><br><span class="line">    ❖ ? ⾮贪婪匹配 </span><br><span class="line">    ❖ +  ⼀个或者多个 </span><br><span class="line">    ❖ () 分组 </span><br><span class="line">    ❖ &#123;&#125; 范围约束 </span><br><span class="line">    ❖ | 匹配多个表达式的任何⼀</span><br></pre></td></tr></table></figure>
</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">awk [选项参数] &apos;script&apos; var=value file(s)</span><br><span class="line">或</span><br><span class="line">awk [选项参数] -f scriptfile var=value file(s)</span><br></pre></td></tr></table></figure>
<h5 id="awk内置变量"><a href="#awk内置变量" class="headerlink" title="awk内置变量"></a>awk内置变量</h5><table>
<thead>
<tr>
<th>变量名</th>
<th>属性</th>
</tr>
</thead>
<tbody>
<tr>
<td>$0</td>
<td>当前记录，一整行</td>
</tr>
<tr>
<td>$1,$2,3….a</td>
<td>当前记录的第n个区域，区域间由FS分隔。</td>
</tr>
<tr>
<td>FS</td>
<td>输入区域分隔符，默认是空格。field separator</td>
</tr>
<tr>
<td>NF</td>
<td>当前记录中的区域个数，就是有多少列。number of field</td>
</tr>
<tr>
<td>NR</td>
<td>已经读出的记录数，就是行号，从1开始。number of record</td>
</tr>
<tr>
<td>RS</td>
<td>输入的记录分隔符默认为换行符。record separator</td>
</tr>
<tr>
<td>OFS</td>
<td>输出区域分隔符，默认也是空格。output record separator</td>
</tr>
<tr>
<td>FNR</td>
<td>当前文件的读入记录号，每个文件重新计算。</td>
</tr>
<tr>
<td>FILENAME</td>
<td>当前正在处理的文件的文件名</td>
</tr>
</tbody>
</table>
<h5 id="选项参数说明："><a href="#选项参数说明：" class="headerlink" title="选项参数说明："></a>选项参数说明：</h5><ul>
<li>-F fs or –field-separator fs<br>指定输入文件折分隔符，fs是一个字符串或者是一个正则表达式，如-F:。</li>
<li>-v var=value or –asign var=value<br>赋值一个用户定义变量。</li>
<li>-f scripfile or –file scriptfile<br>从脚本文件中读取awk命令。</li>
<li>-mf nnn and -mr nnn<br>对nnn值设置内在限制，-mf选项限制分配给nnn的最大块数目；-mr选项限制记录的最大数目。这两个功能是Bell实验室版awk的扩展功能，在标准awk中不适用。</li>
<li>-W compact or –compat, -W traditional or –traditional<br>在兼容模式下运行awk。所以gawk的行为和标准的awk完全一样，所有的awk扩展都被忽略。</li>
<li>-W copyleft or –copyleft, -W copyright or –copyright<br>打印简短的版权信息。</li>
<li>-W help or –help, -W usage or –usage<br>打印全部awk选项和每个选项的简短说明。</li>
<li>-W lint or –lint<br>打印不能向传统unix平台移植的结构的警告。</li>
<li>-W lint-old or –lint-old<br>打印关于不能向传统unix平台移植的结构的警告。</li>
<li>-W posix<br>打开兼容模式。但有以下限制，不识别：/x、函数关键字、func、换码序列以及当fs是一个空格时，将新行作为一个域分隔符；操作符<strong>和</strong>=不能代替^和^=；fflush无效。</li>
<li>-W re-interval or –re-inerval<br>允许间隔正则表达式的使用，参考(grep中的Posix字符类)，如括号表达式[[:alpha:]]。</li>
<li>-W source program-text or –source program-text<br>使用program-text作为源代码，可与-f命令混用。</li>
<li>-W version or –version<br>打印bug报告信息的版本。</li>
</ul>
<hr>
<ul>
<li>record  记录，行</li>
<li>filed  域，区域，字段，列</li>
<li>NF（number of field）表示一行中的区域（列）数量，$NF取最后一个区域。</li>
<li>$符号表示取某个列（区域），$1,2,NF</li>
<li>NR (number of record) 行号,awk对每一行的记录号都有一个内置变量NR来保存，每处理完一条记录NR的值就会自动+1</li>
<li>FS（-F）field separator 列分隔符，以什么把行分隔成多列</li>
<li></li>
</ul>
<h5 id="用法一"><a href="#用法一" class="headerlink" title="用法一"></a>用法一</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">awk &apos;&#123;[pattern] action&#125;&apos; &#123;filenames&#125;   # 行匹配语句 awk &apos;&apos; 只能用单引号</span><br></pre></td></tr></table></figure>
<ul>
<li>awk ‘BEGIN{}END{}’  # 开始和结束</li>
<li>awk ‘/Running/‘     # 正则匹配</li>
<li>awk ‘/aa/,/bb/‘     # 区间匹配</li>
<li>awk ‘$2~/XXX/‘      # 字段匹配 </li>
<li>awk ‘$2!~/XXX/‘     # 字段匹配 </li>
<li>awk ‘NR==2’         # 取第二行</li>
<li>awk ‘NR&gt;1’          # 去掉第一行</li>
</ul>
<hr>
<ul>
<li>-F 参数指定字段分隔符</li>
<li>BEGIN{FS=””} 也可以表示分隔符</li>
<li>$0 代表原来的行</li>
<li>$1 代表第一个字段</li>
<li>$N 代表第N个字段</li>
<li>$NF 代表最后一个字段</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">统计行数</span><br><span class="line">awk &apos;END&#123;print NR&#125;&apos; test.log</span><br><span class="line">wc -l test.log</span><br><span class="line"></span><br><span class="line">分割</span><br><span class="line">awk -F &quot;#&quot; &apos;&#123;print $NF&#125;&apos; awk.txt </span><br><span class="line">awk -F &apos;[#$]&apos; &apos;&#123;print $NF&#125;&apos; awk.txt </span><br><span class="line">分割 （条件动作）</span><br><span class="line">awk -F &quot;#&quot; &apos;NR==2&#123;print $1&#125;&apos; awk.txt</span><br><span class="line">多个模式和动作</span><br><span class="line">awk -F &quot;#&quot; &apos;NR==1&#123;print $NF&#125;NR==3&#123;print $NF&#125;&apos; awk.txt</span><br><span class="line">FNR与NR类似，不过多文件记录不递增，每个文件都从1开始</span><br><span class="line">awk &apos;&#123;print FNR&#125;&apos; awk.txt awk_space.txt</span><br></pre></td></tr></table></figure>
<ul>
<li>正则</li>
</ul>
<table>
<thead>
<tr>
<th>元字符</th>
<th>功能</th>
<th>示例</th>
<th>解释</th>
</tr>
</thead>
<tbody>
<tr>
<td>^</td>
<td>字符串开头</td>
<td>/^cre</td>
<td>匹配所有以cre开头的字符串</td>
</tr>
<tr>
<td>$</td>
<td>字符串结尾</td>
<td>/cre$/</td>
<td>匹配所有以cr结尾的字符串</td>
</tr>
<tr>
<td>.</td>
<td>匹配任意单个字符串</td>
<td>/c..l/</td>
<td>匹配字母c，任意两个字符再以l结尾的行，如 caal</td>
</tr>
<tr>
<td>*</td>
<td>重复0个或多个前一个字符</td>
<td>/a*cal/</td>
<td>匹配0个或多个a之后紧跟cal的行,如cal、aaacal</td>
</tr>
<tr>
<td>+</td>
<td>重复一个字符一次或者一次以上</td>
<td>/a+b/</td>
<td>匹配一个或多个a加b的行</td>
</tr>
<tr>
<td>?</td>
<td>匹配一个或一个前导字符</td>
<td>/a?b/</td>
<td>匹配a或ab的行</td>
</tr>
<tr>
<td>[]</td>
<td>匹配字符组内的任一个字符</td>
<td>/^[abc]/</td>
<td>匹配以字母a或b或c开头的行</td>
</tr>
<tr>
<td>[^]</td>
<td>匹配不再指定字符组内的任一字符</td>
<td>/^[^abc]/</td>
<td>匹配<strong>不</strong>以字母a或b或c开头的行</td>
</tr>
<tr>
<td>()</td>
<td>子表达式组合</td>
<td>/(coo)+/</td>
<td>表示一个或coo组合，当有一些字符需要组合时，使用括号</td>
</tr>
<tr>
<td>\</td>
<td></td>
<td>或</td>
<td>/(cl)</td>
<td>B/</td>
<td>匹配cl或者字母B的行</td>
</tr>
</tbody>
</table>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">以#为分隔符，显示第一列以B开头或最后一列以1结尾的行</span><br><span class="line">awk -F &quot;#&quot; &apos;$1~/^B/&#123;print $0&#125;$NF~/1$/&#123;print $0&#125;&apos; awk.txt</span><br><span class="line">以#为分隔符，显示第一列以B或C开头的行</span><br><span class="line">awk -F &quot;#&quot; &apos;$1~/^B|^C/&#123;print $0&#125;&apos; awk.txt</span><br><span class="line">awk -F &quot;#&quot; &apos;$1~/^[BC]/&#123;print $0&#125;&apos; awk.txt</span><br><span class="line">awk -F &quot;#&quot; &apos;$1~/^(B|C)/&#123;print $0&#125;&apos; awk.txt </span><br><span class="line">awk -F &quot;#&quot; &apos;$1!~/^A/&#123;print $0&#125;&apos; awk.txt </span><br><span class="line"></span><br><span class="line">比较显示</span><br><span class="line">awk &apos;NR==2&#123;print $0&#125;NR==3&#123;print $0&#125;&apos; awk.txt </span><br><span class="line">awk &apos;NR&gt;=1&#123;print $0&#125;&apos; awk.txt </span><br><span class="line">awk &apos;/BAC/,/CBA/&#123;print $0&#125;&apos; awk.txt</span><br></pre></td></tr></table></figure>
<h4 id="计算"><a href="#计算" class="headerlink" title="计算"></a>计算</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">awk &apos;BEGIN&#123;a=8;b=90;print a+b,a-c,a/b,a%b&#125;&apos;</span><br><span class="line"># 98 8 0.0888889 8</span><br><span class="line"></span><br><span class="line">#统计空行</span><br><span class="line">grep &quot;^$&quot; test.log  |wc -l</span><br><span class="line">sed -n &apos;/^$/p&apos; test.log |wc -l</span><br><span class="line">awk &apos;/^$/&apos; test.log |wc -l</span><br><span class="line">awk &apos;/^$/&#123;i=i+1&#125;END&#123;print i&#125;&apos; test.log</span><br><span class="line"></span><br><span class="line"># 累加100</span><br><span class="line">seq 100|awk &apos;&#123;i=i+$0&#125;END&#123;print i&#125;&apos;</span><br><span class="line"></span><br><span class="line">判断</span><br><span class="line">awk &apos;&#123;if($2&gt;=90 )print $0&#125;&apos; score.txt</span><br></pre></td></tr></table></figure>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2020/01/01/linux/linux_三剑客/" data-id="ckcc5iwov007sq4uwsu6b45np" class="article-share-link">Teilen</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/linux/">linux</a></li></ul>

    </footer>
  </div>
  
</article>


  
    <article id="post-linux/linux_awk" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2020/01/01/linux/linux_awk/" class="article-date">
  <time datetime="2020-01-01T07:09:12.000Z" itemprop="datePublished">2020-01-01</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2020/01/01/linux/linux_awk/">linux—三剑客</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h4 id="linux—三剑客"><a href="#linux—三剑客" class="headerlink" title="linux—三剑客"></a>linux—三剑客</h4><h5 id="grep"><a href="#grep" class="headerlink" title="grep"></a>grep</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">awk [选项参数] &apos;script&apos; var=value file(s)</span><br><span class="line">或</span><br><span class="line">awk [选项参数] -f scriptfile var=value file(s)</span><br></pre></td></tr></table></figure>
<h5 id="awk内置变量"><a href="#awk内置变量" class="headerlink" title="awk内置变量"></a>awk内置变量</h5><table>
<thead>
<tr>
<th>变量名</th>
<th>属性</th>
</tr>
</thead>
<tbody>
<tr>
<td>$0</td>
<td>当前记录，一整行</td>
</tr>
<tr>
<td>$1,$2,3….a</td>
<td>当前记录的第n个区域，区域间由FS分隔。</td>
</tr>
<tr>
<td>FS</td>
<td>输入区域分隔符，默认是空格。field separator</td>
</tr>
<tr>
<td>NF</td>
<td>当前记录中的区域个数，就是有多少列。number of field</td>
</tr>
<tr>
<td>NR</td>
<td>已经读出的记录数，就是行号，从1开始。number of record</td>
</tr>
<tr>
<td>RS</td>
<td>输入的记录分隔符默认为换行符。record separator</td>
</tr>
<tr>
<td>OFS</td>
<td>输出区域分隔符，默认也是空格。output record separator</td>
</tr>
<tr>
<td>FNR</td>
<td>当前文件的读入记录号，每个文件重新计算。</td>
</tr>
<tr>
<td>FILENAME</td>
<td>当前正在处理的文件的文件名</td>
</tr>
</tbody>
</table>
<h5 id="选项参数说明："><a href="#选项参数说明：" class="headerlink" title="选项参数说明："></a>选项参数说明：</h5><ul>
<li>-F fs or –field-separator fs<br>指定输入文件折分隔符，fs是一个字符串或者是一个正则表达式，如-F:。</li>
<li>-v var=value or –asign var=value<br>赋值一个用户定义变量。</li>
<li>-f scripfile or –file scriptfile<br>从脚本文件中读取awk命令。</li>
<li>-mf nnn and -mr nnn<br>对nnn值设置内在限制，-mf选项限制分配给nnn的最大块数目；-mr选项限制记录的最大数目。这两个功能是Bell实验室版awk的扩展功能，在标准awk中不适用。</li>
<li>-W compact or –compat, -W traditional or –traditional<br>在兼容模式下运行awk。所以gawk的行为和标准的awk完全一样，所有的awk扩展都被忽略。</li>
<li>-W copyleft or –copyleft, -W copyright or –copyright<br>打印简短的版权信息。</li>
<li>-W help or –help, -W usage or –usage<br>打印全部awk选项和每个选项的简短说明。</li>
<li>-W lint or –lint<br>打印不能向传统unix平台移植的结构的警告。</li>
<li>-W lint-old or –lint-old<br>打印关于不能向传统unix平台移植的结构的警告。</li>
<li>-W posix<br>打开兼容模式。但有以下限制，不识别：/x、函数关键字、func、换码序列以及当fs是一个空格时，将新行作为一个域分隔符；操作符<strong>和</strong>=不能代替^和^=；fflush无效。</li>
<li>-W re-interval or –re-inerval<br>允许间隔正则表达式的使用，参考(grep中的Posix字符类)，如括号表达式[[:alpha:]]。</li>
<li>-W source program-text or –source program-text<br>使用program-text作为源代码，可与-f命令混用。</li>
<li>-W version or –version<br>打印bug报告信息的版本。</li>
</ul>
<hr>
<ul>
<li>record  记录，行</li>
<li>filed  域，区域，字段，列</li>
<li>NF（number of field）表示一行中的区域（列）数量，$NF取最后一个区域。</li>
<li>$符号表示取某个列（区域），$1,2,NF</li>
<li>NR (number of record) 行号,awk对每一行的记录号都有一个内置变量NR来保存，每处理完一条记录NR的值就会自动+1</li>
<li>FS（-F）field separator 列分隔符，以什么把行分隔成多列</li>
<li></li>
</ul>
<h5 id="用法一"><a href="#用法一" class="headerlink" title="用法一"></a>用法一</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">awk &apos;&#123;[pattern] action&#125;&apos; &#123;filenames&#125;   # 行匹配语句 awk &apos;&apos; 只能用单引号</span><br></pre></td></tr></table></figure>
<ul>
<li>awk ‘BEGIN{}END{}’  # 开始和结束</li>
<li>awk ‘/Running/‘     # 正则匹配</li>
<li>awk ‘/aa/,/bb/‘     # 区间匹配</li>
<li>awk ‘$2~/XXX/‘      # 字段匹配 </li>
<li>awk ‘$2!~/XXX/‘     # 字段匹配 </li>
<li>awk ‘NR==2’         # 取第二行</li>
<li>awk ‘NR&gt;1’          # 去掉第一行</li>
</ul>
<hr>
<ul>
<li>-F 参数指定字段分隔符</li>
<li>BEGIN{FS=””} 也可以表示分隔符</li>
<li>$0 代表原来的行</li>
<li>$1 代表第一个字段</li>
<li>$N 代表第N个字段</li>
<li>$NF 代表最后一个字段</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">统计行数</span><br><span class="line">awk &apos;END&#123;print NR&#125;&apos; test.log</span><br><span class="line">wc -l test.log</span><br><span class="line"></span><br><span class="line">分割</span><br><span class="line">awk -F &quot;#&quot; &apos;&#123;print $NF&#125;&apos; awk.txt </span><br><span class="line">awk -F &apos;[#$]&apos; &apos;&#123;print $NF&#125;&apos; awk.txt </span><br><span class="line">分割 （条件动作）</span><br><span class="line">awk -F &quot;#&quot; &apos;NR==2&#123;print $1&#125;&apos; awk.txt</span><br><span class="line">多个模式和动作</span><br><span class="line">awk -F &quot;#&quot; &apos;NR==1&#123;print $NF&#125;NR==3&#123;print $NF&#125;&apos; awk.txt</span><br><span class="line">FNR与NR类似，不过多文件记录不递增，每个文件都从1开始</span><br><span class="line">awk &apos;&#123;print FNR&#125;&apos; awk.txt awk_space.txt</span><br></pre></td></tr></table></figure>
<ul>
<li>正则</li>
</ul>
<table>
<thead>
<tr>
<th>元字符</th>
<th>功能</th>
<th>示例</th>
<th>解释</th>
</tr>
</thead>
<tbody>
<tr>
<td>^</td>
<td>字符串开头</td>
<td>/^cre</td>
<td>匹配所有以cre开头的字符串</td>
</tr>
<tr>
<td>$</td>
<td>字符串结尾</td>
<td>/cre$/</td>
<td>匹配所有以cr结尾的字符串</td>
</tr>
<tr>
<td>.</td>
<td>匹配任意单个字符串</td>
<td>/c..l/</td>
<td>匹配字母c，任意两个字符再以l结尾的行，如 caal</td>
</tr>
<tr>
<td>*</td>
<td>重复0个或多个前一个字符</td>
<td>/a*cal/</td>
<td>匹配0个或多个a之后紧跟cal的行,如cal、aaacal</td>
</tr>
<tr>
<td>+</td>
<td>重复一个字符一次或者一次以上</td>
<td>/a+b/</td>
<td>匹配一个或多个a加b的行</td>
</tr>
<tr>
<td>?</td>
<td>匹配一个或一个前导字符</td>
<td>/a?b/</td>
<td>匹配a或ab的行</td>
</tr>
<tr>
<td>[]</td>
<td>匹配字符组内的任一个字符</td>
<td>/^[abc]/</td>
<td>匹配以字母a或b或c开头的行</td>
</tr>
<tr>
<td>[^]</td>
<td>匹配不再指定字符组内的任一字符</td>
<td>/^[^abc]/</td>
<td>匹配<strong>不</strong>以字母a或b或c开头的行</td>
</tr>
<tr>
<td>()</td>
<td>子表达式组合</td>
<td>/(coo)+/</td>
<td>表示一个或coo组合，当有一些字符需要组合时，使用括号</td>
</tr>
<tr>
<td>\</td>
<td></td>
<td>或</td>
<td>/(cl)</td>
<td>B/</td>
<td>匹配cl或者字母B的行</td>
</tr>
</tbody>
</table>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">以#为分隔符，显示第一列以B开头或最后一列以1结尾的行</span><br><span class="line">awk -F &quot;#&quot; &apos;$1~/^B/&#123;print $0&#125;$NF~/1$/&#123;print $0&#125;&apos; awk.txt</span><br><span class="line">以#为分隔符，显示第一列以B或C开头的行</span><br><span class="line">awk -F &quot;#&quot; &apos;$1~/^B|^C/&#123;print $0&#125;&apos; awk.txt</span><br><span class="line">awk -F &quot;#&quot; &apos;$1~/^[BC]/&#123;print $0&#125;&apos; awk.txt</span><br><span class="line">awk -F &quot;#&quot; &apos;$1~/^(B|C)/&#123;print $0&#125;&apos; awk.txt </span><br><span class="line">awk -F &quot;#&quot; &apos;$1!~/^A/&#123;print $0&#125;&apos; awk.txt </span><br><span class="line"></span><br><span class="line">比较显示</span><br><span class="line">awk &apos;NR==2&#123;print $0&#125;NR==3&#123;print $0&#125;&apos; awk.txt </span><br><span class="line">awk &apos;NR&gt;=1&#123;print $0&#125;&apos; awk.txt </span><br><span class="line">awk &apos;/BAC/,/CBA/&#123;print $0&#125;&apos; awk.txt</span><br></pre></td></tr></table></figure>
<h4 id="计算"><a href="#计算" class="headerlink" title="计算"></a>计算</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">awk &apos;BEGIN&#123;a=8;b=90;print a+b,a-c,a/b,a%b&#125;&apos;</span><br><span class="line"># 98 8 0.0888889 8</span><br><span class="line"></span><br><span class="line">#统计空行</span><br><span class="line">grep &quot;^$&quot; test.log  |wc -l</span><br><span class="line">sed -n &apos;/^$/p&apos; test.log |wc -l</span><br><span class="line">awk &apos;/^$/&apos; test.log |wc -l</span><br><span class="line">awk &apos;/^$/&#123;i=i+1&#125;END&#123;print i&#125;&apos; test.log</span><br><span class="line"></span><br><span class="line"># 累加100</span><br><span class="line">seq 100|awk &apos;&#123;i=i+$0&#125;END&#123;print i&#125;&apos;</span><br><span class="line"></span><br><span class="line">判断</span><br><span class="line">awk &apos;&#123;if($2&gt;=90 )print $0&#125;&apos; score.txt</span><br></pre></td></tr></table></figure>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2020/01/01/linux/linux_awk/" data-id="ckcc5iwpw009dq4uw0zpwrt4a" class="article-share-link">Teilen</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/linux/">linux</a></li></ul>

    </footer>
  </div>
  
</article>


  
    <article id="post-python/python_字典" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2019/10/27/python/python_字典/" class="article-date">
  <time datetime="2019-10-27T03:21:36.000Z" itemprop="datePublished">2019-10-27</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2019/10/27/python/python_字典/">python_dict</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h2 id="python-字典"><a href="#python-字典" class="headerlink" title="python-字典"></a>python-字典</h2><p>－　什么是可散列数据类型<br>　　在 Python 词汇表（<a href="https://docs.python.org/3/glossary.html#term-hashable）中，关于可散" target="_blank" rel="noopener">https://docs.python.org/3/glossary.html#term-hashable）中，关于可散</a> 列类型的定义有这样一段话：<br>如果一个对象是可散列的，那么在这个对象的生命周期中，它的散列值是不变 的，而且这个对象需要实现 __hash__() 方法。另外可散列对象还要有__qe__() 方法， 这样才能跟其他键做比较。如果两个可散列对象是相等的，那么它们的 散列值一定是一样的……  　　<br>　　原子不可变数据类型（str、bytes 和数值类型）都是可散列类型，frozenset 也是可散 列的，因为根据其定义，frozenset 里只能容纳可散列类型。元组的话，只有当一个元 组包含的所有元素都是可散列类型的情况下，它才是可散列的。　　<br>　　一般来讲用户自定义的类型的对象都是可散列的，散列值就是它们的 id() 函数的返 回值，所以所有这些对象在比较的时候都是不相等的。如果一个对象实现了__eq__ 方 法，并且在方法中用到了这个对象的内部状态的话，那么只有当所有这些内部状态都 是不可变的情况下，这个对象才是可散列的。</p>
<ul>
<li>删除元素</li>
</ul>
<ol>
<li>popitem:  　　　 　　　　返回并删除字典中的最后一对键和值</li>
<li>pop(key[,default]): 　　　 删除字典给定键 key 所对应的值，返回值为被删除的值。key值必须给出。 否则，返回default值</li>
<li>clear:　　  　　　　　　　删除字典内所有元素</li>
</ol>
<ul>
<li>获取元素</li>
</ul>
<ol>
<li>dict.get(key, default=None)   　　返回指定键的值，如果值不在字典中返回default值</li>
<li>dict.items()　　　以列表返回可遍历的(键, 值) 元组数组</li>
<li>dict.keys()　　　以列表返回一个字典所有的键</li>
<li>dict.setdefault(key, default=None)　　和get()类似, 但如果键不存在于字典中，将会添加键并将值设为default</li>
</ol>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2019/10/27/python/python_字典/" data-id="ckcc5iwp5008dq4uwbfxap2ao" class="article-share-link">Teilen</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/python/">python</a></li></ul>

    </footer>
  </div>
  
</article>


  


  <nav id="page-nav">
    
    <span class="page-number current">1</span><a class="page-number" href="/page/2/">2</a><a class="page-number" href="/page/3/">3</a><span class="space">&hellip;</span><a class="page-number" href="/page/15/">15</a><a class="extend next" rel="next" href="/page/2/">weiter &raquo;</a>
  </nav>

</section>
        
          <aside id="sidebar">
  
    

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tags</h3>
    <div class="widget">
      <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/tags/Design-Patterns/">Design Patterns</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Git/">Git</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Html/">Html</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Http/">Http</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/JavaScript/">JavaScript</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Sort/">Sort</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/algorithm/">algorithm</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/ali-weixin-pay/">ali/weixin pay</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/docker/">docker</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/elasticsearch/">elasticsearch</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/go/">go</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/hexo/">hexo</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/idea/">idea</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/java/">java</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/jvm/">jvm</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/linux/">linux</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/logstash/">logstash</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mysql/">mysql</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/php/">php</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/pytest/">pytest</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/python/">python</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/springboot/">springboot</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/util/">util</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/vue/">vue</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/wechat/">wechat</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/我的世界/">我的世界</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/消息队列/">消息队列</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/线程/">线程</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget tagcloud">
      <a href="/tags/Design-Patterns/" style="font-size: 16.36px;">Design Patterns</a> <a href="/tags/Git/" style="font-size: 10px;">Git</a> <a href="/tags/Html/" style="font-size: 10px;">Html</a> <a href="/tags/Http/" style="font-size: 12.73px;">Http</a> <a href="/tags/JavaScript/" style="font-size: 15.45px;">JavaScript</a> <a href="/tags/Sort/" style="font-size: 18.18px;">Sort</a> <a href="/tags/algorithm/" style="font-size: 11.82px;">algorithm</a> <a href="/tags/ali-weixin-pay/" style="font-size: 13.64px;">ali/weixin pay</a> <a href="/tags/docker/" style="font-size: 17.27px;">docker</a> <a href="/tags/elasticsearch/" style="font-size: 10px;">elasticsearch</a> <a href="/tags/go/" style="font-size: 11.82px;">go</a> <a href="/tags/hexo/" style="font-size: 10px;">hexo</a> <a href="/tags/idea/" style="font-size: 10px;">idea</a> <a href="/tags/java/" style="font-size: 20px;">java</a> <a href="/tags/jvm/" style="font-size: 11.82px;">jvm</a> <a href="/tags/linux/" style="font-size: 18.18px;">linux</a> <a href="/tags/logstash/" style="font-size: 12.73px;">logstash</a> <a href="/tags/mysql/" style="font-size: 14.55px;">mysql</a> <a href="/tags/php/" style="font-size: 11.82px;">php</a> <a href="/tags/pytest/" style="font-size: 10px;">pytest</a> <a href="/tags/python/" style="font-size: 13.64px;">python</a> <a href="/tags/springboot/" style="font-size: 17.27px;">springboot</a> <a href="/tags/util/" style="font-size: 19.09px;">util</a> <a href="/tags/vue/" style="font-size: 10px;">vue</a> <a href="/tags/wechat/" style="font-size: 10.91px;">wechat</a> <a href="/tags/我的世界/" style="font-size: 10px;">我的世界</a> <a href="/tags/消息队列/" style="font-size: 10.91px;">消息队列</a> <a href="/tags/线程/" style="font-size: 11.82px;">线程</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archiv</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/05/">May 2020</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/04/">April 2020</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/03/">March 2020</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/01/">January 2020</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/10/">October 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/08/">August 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/06/">June 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/04/">April 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/03/">March 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/02/">February 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/01/">January 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/12/">December 2018</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/11/">November 2018</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/10/">October 2018</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/09/">September 2018</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/07/">July 2018</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/06/">June 2018</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/05/">May 2018</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/04/">April 2018</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/03/">March 2018</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/02/">February 2018</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/01/">January 2018</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/12/">December 2017</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">letzter Beitrag</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2020/05/17/linux/linux_shell/">linux—shell</a>
          </li>
        
          <li>
            <a href="/2020/05/16/linux/linux_awk_sed/">linux-awk\sed 示例</a>
          </li>
        
          <li>
            <a href="/2020/04/11/linux/linux_bash/">linux—bash</a>
          </li>
        
          <li>
            <a href="/2020/03/29/hello-world/">Hello World</a>
          </li>
        
          <li>
            <a href="/2020/03/16/go基础/">go基础知识</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2020 vchen<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>


  <link rel="stylesheet" href="/fancybox/jquery.fancybox.css">
  <script src="/fancybox/jquery.fancybox.pack.js"></script>


<script src="/js/script.js"></script>



  </div>
</body>
</html>